package com.shierke.Ume.util

import android.content.Context
import com.shierke.Ume.base.App

/**
 * Create by Ybx
 * on 2020-11-10
 * Desribe:
 */
class BaseConfig private constructor() {

    private val context = App.appContext()
    private val prefs = context.getSharedPrefs()

    companion object {
        private val config = BaseConfig()
        fun instance() = config
    }

    fun Context.getSharedPrefs() = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)

    private fun get(key: String): String {
        val value = prefs.getString(key, "")
        return KeyStoreHelper(context).decrypt(value)
    }


    private fun put(key: String, value: String?) {
        if (value.isNullOrEmpty()) return
        val encrypt = KeyStoreHelper(context).encrypt(value)
        prefs.edit()
            .putString(key, encrypt)
            .commit()
    }



    var accessToken: String?
        get() = get(ACCESSTOKEN)
        set(vale) = put(ACCESSTOKEN, vale)

    var tokenType: String?
        get() = get(TOKENTYPE)
        set(vale) = put(TOKENTYPE, vale)


    var expiresIn: String?
        get() = get(EXPIRESIN)
        set(vale) = put(EXPIRESIN, vale)



    var account: String?
        get() = get(ACCOUNT)
        set(vale) = put(ACCOUNT, vale)


    var authFlag: String?
        get() = get(AUTHFLAG)
        set(vale) = put(AUTHFLAG, vale)


    var webId: String?
        get() = get(WEBID)
        set(vale) = put(WEBID, vale)












}